package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo1 {
    public static void main(String[] args) throws Exception {
        //1.加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.连接数据库
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root","root");
        System.out.println("与数据库建立连接成功");
        //3.创建Statement对象
        Statement stm=con.createStatement();

        /*
        CREATE TABLE userinfo(
            id INT PRIMARY KEY AUTO_INCREMENT,
            username VARCHAR(32),
            passowrd VARCHAR(32),
            nickname VARCHAR(32),
            age INT(3)
        )

        */
        //4.创建SQL语句
        String sql="CREATE TABLE userinfo(\n" +
                "    id INT PRIMARY KEY AUTO_INCREMENT,\n" +
                "    username VARCHAR(32),\n" +
                "    passWord VARCHAR(32),\n" +
                "    nickname VARCHAR(32),\n" +
                "    age INT(3)\n" +
                ")";
        //5.执行SQL语句
        stm.execute(sql);
        System.out.println("创建表成功");
        //6.关闭连接
        con.close();

    }
}
